// pages/index/businessProfile/businessProfile.js
import {
  stats
} from '../../../api.js'
var app = getApp(); //获取App内部的信息
Page({
  data: {
    totalIncome: 0, //总成交金额
    totalReceive: 0, //总收入金额
    storageProductsNumber: 0, // 库存商品数量
    storageProductMoney: 0, // 库存商品总金额
    procurementMoney: 0, // 回收资金
    buyersCountOffline: 0, // 线下支付买家数
    ordersCountOffilne: 0, // 支付订单数
    refundOrdersCount: 0, // 退款笔数
    refundMoneyTotal: 0, //退款金额总数
    updateTime: '',
  },
  onLoad: function(options) {
    let _this = this;
    console.log("aaa")
    stats({
      token: app.globalData.token
    }).then(res => {
      if (res.data.code == 666) {
        let data = res.data.data.generalBusiness;
        _this.setData({
          totalIncome: data.totalIncome,
          totalReceive: data.totalReceive,
          storageProductsNumber: data.storageProductsNumber,
          storageProductMoney: data.storageProductMoney,
          procurementMoney: data.procurementMoney,
          buyersCountOffline: data.buyersCountOffline,
          ordersCountOffilne: data.ordersCountOffilne,
          refundOrdersCount: data.refundOrdersCount,
          refundMoneyTotal: data.refundMoneyTotal,
        })
      } else if (res.data.code == 111111) {
        wx.showToast({
          title: '登录失效，请重新登录',
          icon: 'none',
        })
        setTimeout(function() {
          wx.reLaunch({
            url: '/pages/user/login/login',
          })
        }, 1500)
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }


    })
    let now = new Date();
    let myTime = now.toLocaleDateString();
    // let month = now.getMonth() - 0 < 11 ? '0' + now.getMonth() - 0 + 1 : now.getMonth();
    // let date = now.getDate();
    // myTime = `${month} - ${date}`;
    // console.log(`${month}-${date}`)
    this.setData({
      updateTime: myTime
    })
  }
})